package cn.edu.hadoop;

import org.apache.hadoop.conf.Configuration;
import org.apache.hadoop.fs.Path;
import org.apache.hadoop.io.IntWritable;
import org.apache.hadoop.io.Text;
import org.apache.hadoop.mapreduce.lib.input.FileInputFormat;
import org.apache.hadoop.mapreduce.lib.output.FileOutputFormat;
import org.apache.hadoop.mapreduce.Job;

public class WordCountDriver {
    public static void main(String[] args) throws Exception{
//        使用Job封装MR的相关信息
        Configuration conf = new Configuration();
//        配置MR的运行模式
        conf.set("mapreduce.framework.name","local");
        Job job = Job.getInstance(conf);
//        指定MR Job jar包的运行主类
        job.setJarByClass(WordCountDriver.class);
//        指定MR的Mapper Reduce类
        job.setMapperClass(WordCountMapper.class);
        job.setReducerClass(WordCountReducer.class);
//        设置业务逻辑Mapper类输出的key和value的数据类型
        job.setMapOutputKeyClass(Text.class);
        job.setMapOutputValueClass(IntWritable.class);
//        设置业务逻辑Reduce类输出的key和value的数据类型
        job.setOutputKeyClass(Text.class);
        job.setOutputValueClass(IntWritable.class);
//        处理数据的位置
        FileInputFormat.setInputPaths(job, "./input");
//        输出结果所保存的位置
        FileOutputFormat.setOutputPath(job, new Path("./output"));
//        提交程序并且监控打印程序执行情况
        boolean res = job.waitForCompletion(true);
        System.exit(res ? 0:1);
    }
}
